package StatePattern.example2;

public class ThreadContext {
    private ThreadState threadState;

    public ThreadContext() {
        threadState = NewState.getInstance();
    }

    public ThreadState getThreadState() {
        return threadState;
    }

    public void setThreadState(ThreadState threadState) {
        this.threadState = threadState;
    }

    public void start() {
        threadState.start(this);
    }

    public void suspend() {
        threadState.suspend(this);
    }

    public void resume() {
        threadState.resume(this);
    }

    public void stop() {
        threadState.stop(this);
    }


    public void getCpu() {
        threadState.getCpu(this);
    }

    @Override
    public String toString() {
        return "ThreadContext{" +
                "线程状态=" + threadState.getStateName() +
                '}';
    }
}
